package com.study.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @author study
 * @version 1.0
 * @date 2020/8/8 22:07
 */
@Configuration
public class ThreadPoolConfig {
    //https://crossoverjie.top/JCSprout/#/thread/ThreadPoolExecutor
    @Bean(value = "nvshensThreadPool")
    public ExecutorService buildnvshensThreadPool() {

        ThreadFactory nameThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("ns-queue-thread-%d").build();
        ExecutorService pool = new ThreadPoolExecutor(
                6,
                8,
                0L,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(100),
                nameThreadFactory, new ThreadPoolExecutor.AbortPolicy());
        return pool;
    }
}
